import request from './request'

// 用户注册
export const register = (data) => {
  return request({
    url: '/admin/register',
    method: 'post',
    data
  })
}

// 用户登录
export const login = (data) => {
  return request({
    url: '/admin/login',
    method: 'post',
    data
  })
}

// 获取用户信息
export const getUserInfo = () => {
  return request({
    url: '/admin/info',
    method: 'get'
  })
}

// 更新用户信息
export const updateUserInfo = (data) => {
  return request({
    url: '/admin/info',
    method: 'put',
    data
  })
}

// 修改密码
export const changePassword = (oldPassword, newPassword) => {
  return request({
    url: '/admin/changePassword',
    method: 'post',
    params: {
      oldPassword,
      newPassword
    }
  })
}

// 检查用户名是否存在
export const checkUsername = (username) => {
  return request({
    url: '/admin/checkUsername',
    method: 'get',
    params: { username }
  })
}

// 检查手机号是否存在
export const checkPhone = (phone) => {
  return request({
    url: '/admin/checkPhone',
    method: 'get',
    params: { phone }
  })
}

// 检查邮箱是否存在
export const checkEmail = (email) => {
  return request({
    url: '/admin/checkEmail',
    method: 'get',
    params: { email }
  })
}
// 管理端：获取用户列表
export const getUserList = (params) => {
  return request({
    url: '/admin/user/list',
    method: 'get',
    params
  })
}

// 管理端：添加用户
export const addUser = (data) => {
  return request({
    url: '/admin/user',
    method: 'post',
    data
  })
}

// 管理端：编辑用户
export const updateUser = (id, data) => {
  return request({
    url: `/admin/user/${id}`,
    method: 'put',
    data
  })
}

// 管理端：删除用户
export const deleteUser = (id) => {
  return request({
    url: `/admin/user/${id}`,
    method: 'delete'
  })
}

// 管理端：根据ID获取用户
export const getUserById = (id) => {
  return request({
    url: `/admin/user/${id}`,
    method: 'get'
  })
}